<?php

namespace App\Http\Controllers\Api\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Api\Home\BaseController;
use App\Http\Requests\Article\Store;
use App\Http\Requests\Article\Update;
use App\Models\Article;
use File;


class ArticleController extends BaseController
{
    private $return = array(
        'code' => 1,
        'msg' => ''
    );
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Article $article,Request $request)
    {
        $params = $request->all();
        $result = $article->getList($params);
        if(!$result){
            $this->return['msg'] = '查询失败';
        }else{
            $this->return['code'] = 0;
            $this->return['data'] = $result;
        }
        return response()->json($this->return);
    }


    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($code,Article $article)
    {
        $result = $article->getDataByCode($code);
        if ($result) {
            $this->return['code'] = 0;
            $this->return['data'] = $result->toArray();
        }else {
            $this->return['msg'] = '请求失败';
        }
        return response()->json($this->return);
    }

}
